package com.warski.wonderfires.page.led;

import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.recyclerview.widget.RecyclerView;
import com.warski.wonderfires.R;
import java.util.ArrayList;


public class RecyclerAdapter extends RecyclerView.Adapter<RecyclerAdapter.AuthorViewHolder> {

    private ArrayList<String> mList;
    public RecyclerAdapter(ArrayList<String> list){
        mList = list;
    }
    @Override
    public AuthorViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        LayoutInflater inflater = LayoutInflater.from(parent.getContext());
        View childView = inflater.inflate(R.layout.item, parent, false);

        AuthorViewHolder viewHolder = new AuthorViewHolder(childView);
        int parentHeight = parent.getHeight();
        ViewGroup.LayoutParams layoutParams = viewHolder.itemView.getLayoutParams();
        //显示条数
        layoutParams.height =  (parentHeight / 9);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(AuthorViewHolder holder, int position) {

        String line = mList.get(position);
        holder.mNickNameView.setText(line);
        Log.d("onBindViewHolder","position is : " + position);

    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    class AuthorViewHolder extends RecyclerView.ViewHolder {

        TextView mNickNameView;
        public AuthorViewHolder(View itemView) {
            super(itemView);

            mNickNameView = (TextView) itemView.findViewById(R.id.tv_nickname);

        }
    }

}
